package com.wx.studentManage.service.Impl;

import com.wx.studentManage.mapper.SignMapper;
import com.wx.studentManage.model.Sign;
import com.wx.studentManage.service.SignService;
import com.wx.studentManage.util.MyDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("signService")
public class SignServiceImpl implements SignService {

    @Autowired
    private SignMapper signMapper;

    @Override
    public String addSign(List<Sign> signs) {
        int result = signMapper.addSign(signs);
        if (result > 0){
            return "success";
        } else {
            return "false";
        }
    }

    @Override
    public boolean checkSign(Sign sign) {
        Sign s = signMapper.checkSign(sign);
        return s != null;
    }

    @Override
    public List<Sign> getSignList(Map<String, Object> data) {
        int page = Integer.parseInt((String) data.get("pageNum"));
        int size = Integer.parseInt((String)data.get("pageSize"));
        data.put("pageNum",(page-1)*size);
        data.put("pageSize",size);
        return signMapper.getSignList(data);
    }

    @Override
    public int getSelectCount(Map<String, Object> data) {
        return signMapper.getSelectCount(data);
    }

    @Override
    public Sign getSignById(Integer id) {
        return signMapper.getSignById(id);
    }

    @Override
    public int delSign(Sign sign) {
        sign.setUpdateTime(MyDate.getDate());
        return signMapper.delSign(sign);
    }

    @Override
    public String batchDeletion(List<Integer> ids) {
        Map params = new HashMap();
        params.put("ids",ids);
        params.put("updateTime",MyDate.getDate());
        int result = signMapper.batchDeletion(params);
        if (result>0){
            return "success";
        }else {
            return "false";
        }
    }
}
